package com.itheima.controller;

import com.itheima.anno.Log;
import com.itheima.pojo.Emp;
import com.itheima.pojo.LoginInfo;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

// 登录的控制器
@RestController
public class LoginController {
    // 依赖员工的业务层
    @Autowired
    private EmpService empService;

    /**
     * 根据账号密码登录
     * @param emp
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Emp emp) {
        // 调用业务层去根据账号密码登录
        LoginInfo loginInfo = empService.login(emp);

        if (loginInfo != null) {
            // 响应结果
            return Result.success(loginInfo);
        } else {
            return Result.error("用户名或密码错误!");
        }
    }
}
